#include "logo.h"

void getCmd(void)
{

  char *command;
  char *cmd;
  char *cmdName[]=
       {"MAKE","PRINT","RUN","IF","TEST","IFTRUE","IFFALSE","REPEAT","ERASE",
       "ERASEALL","WAIT","LOAD","SAVE","TO","OUTPUT","STOP"};
  int cmdNumber= sizeof(cmdName)/sizeof(char*);
  void (*cmdP[])(void)=
       {make,print,run,cmdIf,test,iftrue,iffalse,repeat,erase,eraseall,wait,load,save,
        to,output,stop};
  int i;
  int j;
  char *ans;
  char ansStr[MAXVALUE] ="\0";
  char str[MAXVALUE] ="\0";
  char cmdStr[MAXVALUE] ="\0";
  
  command=str;
  ans=ansStr;
  printf("in getCmd\n");
  strcpy(command,getInput());
  while (command[0] =='[')
  {
        command=command +1;
  }
  sscanf(command,"%[A-Z]",command);
  printf("cmd is %s\n",command);
  for (i= 0; i< cmdNumber; i++)
      {
          if (!strcmp(command,cmdName[i]))
             {
                             (*cmdP[i])();
                             return;
                             break;
             }
      }
  printf("cmd is %s\n",command);
  strcpy(cmd,command);
  for (j=0;j<toLen;j++)             //find to
  {
      if (!strcmp(command,toName[j][0]))
      {
         printf("cmd is %s\n",cmd);
         putInput(cmd);
         strcpy(ans,runTo());
         return ;
      }
  }
  printf("Please check your command\n");
  return;
}
/*
//  printf("welcome to getcmd\n");
  scanf("%s", &command);
//  printf("%s\n",command);
      if (!strcmp(command, "MAKE"))
      {
//        printf("welcome to make!\n");
        c = getchar();
        strcpy(a, getWord());
        strcpy(b, getValue());
//        printf("welcome to make!------%s------%s------\n", a, b);

        make(a, b);
      }
      else
      {
        if (!strcmp(command, "PRINT"))
        {
        c = getchar();
        printf("%s\n",getValue());
//        printf("hahaha\n");
        }
        else
        {
           printf("PLEASE CHECK OUT YOUR COMMAND\n");
        }
      }

}*/
